package liuwh.mina.basic.tcp.server.tiemserver.server;

import java.io.IOException;
import java.net.InetSocketAddress;

import liuwh.mina.basic.tcp.server.tiemserver.codec.TimeResponseCodecFactory;

import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

public class MinaTimeServer {

	/**
	 * @author liuwenhao 2011-8-16 上午10:13:07
	 * @param args
	 */
	public static void main(String[] args) {
		
		NioSocketAcceptor acceptor = new NioSocketAcceptor();
		acceptor.getFilterChain().addLast("logger", new LoggingFilter());
		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TimeResponseCodecFactory(true)));
		
		acceptor.setHandler(new TimeServerHandler());
		
		acceptor.getSessionConfig().setReadBufferSize(1024);
		acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
		
		try {
			acceptor.bind(new InetSocketAddress(8985));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
